<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<title>${aier_title}</title>
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />

<link rel="stylesheet" href="${aier_css_url}social/module/reset.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/btn.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/icon.css" />
<link rel="Stylesheet" href="${aier_css_url}social/module/emotion.css" />
<link rel="Stylesheet" href="${aier_css_url}social/module/homeside.css" />
<link rel="stylesheet" href="${aier_css_url}social/user/userMessage/usermessage.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/xxs.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}ui.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript"
	src="${aier_js_url}emotion/xxsemotion.2.js"></script>
<script type="text/javascript" src="${aier_js_url}trantime/jquery-aier.js"></script>

</head>
<body>

	<!-- 顶栏 -->
	<s:action name="userhomecomm_homeHead" namespace="/user" executeResult="true"></s:action>
	<!-- 顶栏结束 -->


	<div class="window-content">

		<!-- wrap  -->
		
		<div class="wrap wrap-message wrap-msg wrap-msg-letter wrap-tri-col clearfix">

			<!-- 主侧栏 -->
			<s:action name="usermessage_msgSide" namespace="/user" executeResult="true"></s:action>


			<!-- 主区域 (右  -->
			<div class="msg-main clearfix">
				<div class="msg-stream">
					<div class="msg-title title">
						<div class="group">
							私信
						</div>
					</div>
					<!-- 原型图上暂时没有功能按钮 -->
					<div class="msg-title-function clearfix">
						<div class="function-left clearfix">
							<a class="btn btn-normal-orange" id = "delete">
								<span>删除所有私信</span>
							</a>
						</div>

					</div>
					
					<div class="msg-list msg-list-letter clearfix">

						<div class="msg-talking-box close">
							<div class=""></div>
							<textarea name="" id="msgTalkingBox" class="letter-textarea"></textarea>
							<div class="submit-bar clearfix">
								<a class="btn-emotion">
									<i class="icon-1 icon-1-emotion"></i>
								</a>
								<a class="btn-submit btn-normal-orange btn-orange-2">
									<span>发送</span>
								</a>
							</div>
						</div>
						<!-- / 发送框 -->

						<!-- 消息列表开始 -->
						<div class="msg-talking-log" id = "letter">
					
	
						</div>
						<!-- /消息列表结束 -->
					</div>
					<div id = "page"></div>

				</div>
				<div id="dialogDeleteOne" style="display: none;" title="删除">
					<p>确认删除这条私信吗</p>
				</div>
				<div id="deleteConfirm" style="display: none;" title="删除全部">
	                <p>确认要删除所有私信吗?</p>
	            </div>

                <!-- 右栏 -->
                <s:action name="userhomecomm_homeRight" namespace="/user" executeResult="true"></s:action>
			</div>

			<!-- 返回顶部 -->
			<s:action name="userhomecomm_backToTop" namespace="/user" executeResult="true"></s:action>
			<!-- end 返回顶部 -->



		</div>
		<!-- footer copyright -->
		<s:action name="userhomecomm_homeFooter" namespace="/user" executeResult="true"></s:action>
		<!-- /footer copyright -->
	</div>




<script type="text/javascript">
    var lid = "${lid}";
    var ruid = "${ruid}";
    var suid = "${suid}";
    var uid;
    var ldidStr = "";
    var page = 1;       // 当前页
    var page_size = 10; // 每页的记录数
    
    $('.btn-emotion').click(function(){
        
        $(this).sinaEmotion({
            emotionUrl: '${aier_js_url}trantime/emotions.js',
            target : $('#msgTalkingBox')
        });
	});
    $(document).ready(function() {
        // 获取关注分组
        var fun=function(data){
            if(data.s==1){
                var c = "";
                for (var i=0;i<data.fgList.length;i++) {
                    if (data.fgList[i].name == "特别关注") {
                        c += "<div class='tab-normal'><a class='btn' href='${aier_url}user/userhomeforums_homeForums.shtml?fgid="+data.fgList[i].fgid+"'><em class='icon-1 icon-1-teguan'></em><span>"+data.fgList[i].name+"</span></a></div>";
                    } else {
                        c += "<div class='tab-normal'><a class='btn' href='${aier_url}user/userhomeforums_homeForums.shtml?fgid="+data.fgList[i].fgid+"'><em class='icon-1 icon-1-weifen'></em><span>"+data.fgList[i].name+"</span></a></div>";
                    }
                    
                }
                $("#group").html(c);
                
            }
        };
        exeAjax(
             ajaxUrl("${aier_url}${aier_urijs}usermyfollow_searchFollowGroup${aier_suffix}"),
             fun,{
        });
        searchLetter(lid,page);
    });
    
    function searchLetter(lid,nowpage) {
        page = nowpage;
        var fun=function(data){
            if(data.s==1){
                if (data.ldList == null || data.ldList.length == 0) {
                    window.location.href = "${aier_url}${aier_uri}usermessage_userMessageLetter${aier_suffix}";
                }
                var html = "";
                uid = data.uid;
                if (uid == ruid) {
			        ruid = suid;
			        suid = uid;
			    }
                for (var i=0;i<data.ldList.length;i++) {
                    var ld = data.ldList[i];
                    ldidStr += ld.ldid +",";
                    if (uid == ld.suid) {
                        html += '<div class="msgt-item msgt-self" data-msgtid = "'+ld.ldid+'">';
                    } else {
                        html += '<div class="msgt-item msgt-other clearfix" data-msgtid = "'+ld.ldid+'">';
                    }
                    html +='<div class="msgt-avatar"><a href="${aier_url}user/uccomm_userCenter.shtml?in_uid='+ld.suid+'"><img src="${get_picturl_url}small/'+ld.headimg+'" alt=""></a></div>';
                    html +='<div class="msgt-content-box"><div class="arrow"><em>♦</em><span>♦</span></div><div class="screen"><a href="javascript:void(0);"><span>x</span></a></div>';
                    html += '<div class="content"><div class="text">'+ld.content+'</div></div></div></div>';
                }
                $("#letter").html(html);
                $("#letter .text").each(function(){
                	$(this).tranText({
                		emotionUrl: '${aier_js_url}trantime/emotions.js'
                	});
                });
                
                
                // 删除这条私信
				$('.screen').click(function(){
				    var thisLetter = $(this).closest('.msgt-item').attr('data-msgtid');
				        
				    $('#dialogDeleteOne').dialog({
				        //背景变暗
				        modal : true,
				        autoOpen : false,
				        show : "fade",
				        hide : "fade",
				        width : "360",
				        height : "280",
				        buttons : {
				            "确定" : function() {
				               var fun=function(data){
				                   if(data.s==1){
				                        searchLetter(lid,page);
				                         $('#dialogDeleteOne').dialog("close");
				                    } else {
				                       $().message("删除失败，请稍后再试！");
				                    }
				                };
				                exeAjax(
				                     ajaxUrl("${aier_url}${aier_urijs}usermessage_deleteLetterByLdid${aier_suffix}"),
				                     fun,{
				                         "ldidStr":thisLetter
				                });
				
				            },
				            "取消" : function() {
				                $('#dialogDeleteOne').dialog("close");
				            }
				        }
				    });
				    
				    $('#dialogDeleteOne').dialog('open');
				});
                // 更新分页显示
                page = data.page;
                toLoadPage(page, page_size, data.page_count, data.count, "page", "searchLetter", lid, null);
                if (data.count == 0) {
                    $("#page").css("display","none");
                } else {
                    $("#page").css("display","block");
                }
            }
        };
        exeAjax(
             ajaxUrl("${aier_url}${aier_urijs}usermessage_searchLetterDetail${aier_suffix}"),
             fun,{
             "page":page,
             "page_size":page_size,
             "lid":lid
        });
    }
    

// 删除所有私信
$("#delete").click(function(){

    $("#deleteConfirm").dialog(
            {
                //背景变暗
                modal : true,
                autoOpen : false,
                show : "fade",
                hide : "fade",
                width : "340",
                height : "220",
                buttons : {
                    "确定" : function() {
                        var fun=function(data){
				            if(data.s==1){
				                $("#deleteConfirm").dialog("close");
				                window.location.href = "${aier_url}${aier_uri}usermessage_userMessageLetter${aier_suffix}";
				            } else {
				               $("#deleteConfirm").dialog("close");
				               $().message("删除失败，请稍后再试！");
				            }
				        };
				        exeAjax(
				             ajaxUrl("${aier_url}${aier_urijs}usermessage_deleteLetterByLdid${aier_suffix}"),
				             fun,{
				                "ldidStr":ldidStr
				        });
                    },
                    "取消" : function() {
                        $(this).dialog("close");
                    }
            }
        });
        $("#deleteConfirm").dialog("open");

});
    
    
$('#msgTalkingBox').click(function(){
	var thisarea = $(this);
		thisBox = $(this).closest('.msg-talking-box').removeClass('close');
	
});


// 发私信
$('.btn-submit').click(function() {
    var content = $("#msgTalkingBox").val();
    if (content == null || content.trim().length == 0) {
        $().message("私信内容不能为空！");
        return;
    }
    if (content.length > 300) {
        $().message("私信内容太长！");
        return;
    }
    
    var fun=function(data){
        if(data.s==1){
            searchLetter(lid,page);
            $("#msgTalkingBox").val("");
        } else {
           $().message("发送失败，请稍后再试！");
        }
    };
    exeAjax(
         ajaxUrl("${aier_url}${aier_urijs}usermessage_sendLetter${aier_suffix}"),
         fun,{
             "ruid":ruid,
             "content":content
    });
    
});  

// 跳转到家校联系薄
    function hsConBook() {
        // 判断是否付费

        // 判断身份（家长或老师）

        // 教师（tid）
        //window.location.href = "${aier_url}user/userhscb_userTeaHSConBook.shtml?tid=2&&cid=1";
        var fun = function(data) {
            if (data.s == 1) {

                if (data.type == 0) {
                    $().message("您目前没有权利进入家校联系薄！");
                    return;
                } else if (data.type == 1 || data.type == 3) {
                    if (data.classList != null && data.classList.length > 0) {
                        window.location.href = "${aier_url}user/userhscb_userTeaHSConBook.shtml?cid="
                                + data.classList[0].cid +"&type="+data.type;
                    } else {
                        window.location.href = "${aier_url}user/userhscb_userTeaHSConBook.shtml?type="+data.type;
                    }

                } else if (data.type == 2) {
                    window.location.href = "${aier_url}user/userhscb_userChiHSConBook.shtml?type="+data.type;
                }

            }
        };
        exeAjax(
                ajaxUrl("${aier_url}${aier_urijs}userhscb_searchClassList${aier_suffix}"),
                fun, {});

    }

</script>

</body>
</html>